import { Controller } from "../../mvc/core/Controller";
import { PetIslandApplyController } from "../view/petIsland/controller/PetIslandApplyController";
import { PetIslandMapController } from "../view/petIsland/controller/PetIslandMapController";
import { PetIslandPowerBaseController } from "../view/petIsland/controller/PetIslandPowerBaseController";
import { PetIslandFightController } from "../view/petIsland/controller/PetIslandFightController";
import { DataEvent } from "../events/DataEvent";
import { GameProxy } from "../mvc/GameProxy";
import { ResFileConst } from "../resource/ResFileConst";
import { EffectManager } from "../manager/EffectManager";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SRobIslandResult } from "../../../Message/Game/SRobIslandResult";
import { ERobIslandResult } from "../../../Message/Game/ERobIslandResult";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { PetIslandBtn } from "../view/petIsland/PetIslandBtn";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { EPublicCommand } from "../../../Message/Command/EPublicCommand";
//class PetIslandController
    
    export  class PetIslandController extends Controller
    {
        constructor()
        {
            
            super();this.initController();
            return;
        }

        /* internal  */initController(): void
        {
            this.applyController = new PetIslandApplyController();
            this.mapController = new PetIslandMapController();
            this.powerBaseController = new PetIslandPowerBaseController();
            this.fightController = new PetIslandFightController();
            return;
        }

        public showView(): void
        {
            this.mapController.view.show();
            return;
        }

        /* internal  */closeAllPanel(): Boolean
        {
            if (this.applyController.applyPanel && !this.applyController.applyPanel.isHide) 
            {
                this.applyController.view.hide();
                return true;
            }
            if (this.mapController.petIslandMapPanel && !this.mapController.petIslandMapPanel.isHide) 
            {
                this.mapController.view.hide();
                return true;
            }
            if (this.powerBaseController.petIslandPowerBasePanel && !this.powerBaseController.petIslandPowerBasePanel.isHide) 
            {
                this.powerBaseController.view.hide();
                return true;
            }
            return false;
        }

        /* internal  */onClickPetIslandBtnHandler(arg1: DataEvent): void
        {
            if (!this.closeAllPanel()) 
            {
                if (cache.guild.myGuildInfo) 
                {
                    cache.petIsland.needShowView = true;
                    GameProxy.petIsland.getSignUpInfo();
                }
                else 
                {
                    this.applyController.view.show();
                    this.applyController.applyPanel.operateBtnStyleName = ResFileConst.PetIslandApplyJoinGuildBtn;
                }
            }
            return;
        }

        /* internal  */petIslandOpen(arg1: Object): void
        {
            this.petIslandBtn.show();
            EffectManager.glowFilterReg(this.petIslandBtn, null, 1, 10, 0, 5);
            return;
        }

        /* internal  */petIslandClose(arg1: Object): void
        {
            this.petIslandBtn.hide();
            this.closeAllPanel();
            return;
        }

        /* internal  */onPetIslandResultHandler(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SRobIslandResult;
            var loc2=loc1.result;
            switch (loc2) 
            {
                case ERobIslandResult._ERobIslandResultJoinSuccess:
                {
                    break;
                }
                case ERobIslandResult._ERobIslandResultAttackSuccess:
                {
                    if (!this.mapController.discardPanel.isHide) 
                    {
                        this.mapController.discardPanel.hide();
                    }
                    break;
                }
                case ERobIslandResult._ERobIslandResultMemberOperSuccess:
                {
                    this.powerBaseController.posChangePanel.hide();
                    GameProxy.petIsland.getGuildMemberInfo();
                    break;
                }
                case ERobIslandResult._ERobIslandResultQuitSuccess:
                {
                    this.mapController.view.hide();
                    this.powerBaseController.view.hide();
                    break;
                }
                case ERobIslandResult._ERobIslandResultPlaceInfo:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandSetMapItemTipPosition));
                    break;
                }
                case ERobIslandResult._ERobIslandResultObserveSuccess:
                {
                    this.fightController.view.show();
                    break;
                }
            }
            return;
        }

        /* internal  */get petIslandBtn(): PetIslandBtn
        {
            if (!this._petIslandBtn) 
            {
                this._petIslandBtn = new PetIslandBtn();
            }
            return this._petIslandBtn;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.PetIslandBtnClick, this.onClickPetIslandBtnHandler);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicRobIslandOpen, this.petIslandOpen);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicRobIslandClose, this.petIslandClose);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicRobIslandResult, this.onPetIslandResultHandler);
            return;
        }

        private /* var */_petIslandBtn: PetIslandBtn;

        public /* var */applyController: PetIslandApplyController;

        public /* var */mapController: PetIslandMapController;

        public /* var */powerBaseController: PetIslandPowerBaseController;

        public /* var */fightController: PetIslandFightController;
    }
